package fenetres;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class Acceuil extends JFrame implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String F = null;
	JFrame fenPrinc;
	JPanel menuPanel, fonPanel, loginPanel;
	// menu principale
	JMenuBar menuPrinc;
    JMenuItem deconMenu, conMenu;
	JMenuItem addRestau, searchRestau, listRestau, modifRestau;
	JMenuItem addPlat, searchPlat, listPlat, modifPlat;
	JMenuItem addComment, delComment, listComment;
	JPanel fenPanel, imagePanel;

	// @SuppressWarnings("deprecation")
	public Acceuil() {
		fenPrinc = new JFrame();
		fenPanel = new JPanel();
		fenPanel.setBounds(0, 0, 800, 70);
		
		//fenPanel.setBackground(Color.WHITE);
		imagePanel = new JPanel();
		imagePanel.setBounds(0, 70, 800, 730);

		etablishMenu();
		etablishEntete();
		etablishImage();

		fenPrinc.getContentPane().setLayout(null);

		fenPrinc.getContentPane().add(fenPanel);
		fenPrinc.getContentPane().add(imagePanel);

		// fenetre titre
		fenPrinc.setTitle("GESTION DE RECOMMANDATION DE RSTAURANT");
		fenPrinc.setSize(800, 730);
		// fermeture de la fentre
		fenPrinc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		fenPrinc.setVisible(true);

		// fenPrinc.pack();

		// recuperation la taille de la fenetre
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		fenPrinc.setLocation((screen.width - this.getSize().width) / 2,
				(screen.height - this.getSize().height) / 2);
	    
		fenPrinc.setJMenuBar(menuPrinc);
		fenPrinc.setLocationRelativeTo(null);
		// fenPrinc.getContentPane().add(fenPanel,BorderLayout.CENTER);
		// fenPrinc.pack();

	}

	private void etablishEntete() {
		// TODO Auto-genetrated method stub
		JLabel enteteLabel = new JLabel("Bien-venue sur la plateforme");
		enteteLabel.setFont(new java.awt.Font("Century Schoolbook L",java.awt.Font.ITALIC, 20));
		enteteLabel.setForeground(Color.blue);
		fenPanel.setLayout(null);
		fenPanel.add(enteteLabel);
		enteteLabel.setBounds(250, 0, 500, 30);
	}

	private void etablishMenu() {
		// TODO Auto-generated method stub
		// menuPrincipale
		menuPrinc = new JMenuBar();
		
		JMenu fileMenu= new JMenu("Fichier");
		conMenu= new JMenuItem("Connexion");
		conMenu.addActionListener(this);
		deconMenu = new JMenuItem("Quitter");
		deconMenu.addActionListener(this);
		// menu Restaurant
		JMenu restMenu = new JMenu("Restaurant");
		restMenu.setForeground(Color.BLACK);
		addRestau = new JMenuItem("Ajouter Restaurant");
		addRestau.addActionListener(this);
		modifRestau = new JMenuItem("Modifier Restaurant");
		modifRestau.addActionListener(this);
		listRestau = new JMenuItem("Afficher Restaurants");
		listRestau.addActionListener(this);
		searchRestau = new JMenuItem("Chercher Restaurant");
		searchRestau.addActionListener(this);

		// menu palt
		JMenu platMenu = new JMenu("Plat");
		addPlat = new JMenuItem("Ajouter Plat");
		addPlat.addActionListener(this);
		modifPlat = new JMenuItem("Modifier Plat");
		modifPlat.addActionListener(this);
		listPlat = new JMenuItem("Afficher Plat");
		listPlat.addActionListener(this);
		searchPlat = new JMenuItem("Chercher Plat");
		searchPlat.addActionListener(this);
		
		// menu Commentaire
		JMenu commentMenu = new JMenu("Commentaire");
		addComment = new JMenuItem("Ajouter Commentaire");
		addComment.addActionListener(this);
		listComment = new JMenuItem("Afficher Commentaires");
		listComment.addActionListener(this);
		delComment = new JMenuItem("Supprimer Commentaire");
		delComment.addActionListener(this);
		fileMenu.add(conMenu);
        fileMenu.add(deconMenu);
        
        
		restMenu.add(addRestau);
		restMenu.add(modifRestau);
		restMenu.add(listRestau);
		restMenu.add(searchRestau);

		platMenu.add(addPlat);
		platMenu.add(modifPlat);
		platMenu.add(listPlat);
		platMenu.add(searchPlat);

		commentMenu.add(addComment);
		commentMenu.add(listComment);
		commentMenu.add(delComment);

		menuPrinc.add(fileMenu);
		menuPrinc.add(restMenu);
		menuPrinc.add(platMenu);
		menuPrinc.add(commentMenu);

	}

	private void etablishImage() {
		// TODO Auto-generated method stub

		JLabel imageLab = null;
		JLabel imageLab1 = null;
		JLabel imageLab2 = null;

		try {
			BufferedImage picture = ImageIO.read(new File("image/TPGL.jpeg"));
			imageLab = new JLabel(new ImageIcon(picture));

			BufferedImage picture1 = ImageIO.read(new File("image/TPGL2.jpeg"));
			imageLab1 = new JLabel(new ImageIcon(picture1));

			BufferedImage picture2 = ImageIO.read(new File("image/TPGL3.jpeg"));
			imageLab2 = new JLabel(new ImageIcon(picture2));
		} catch (IOException e) {
			e.printStackTrace();
		}
		imageLab.setBounds(40, 10, 400, 300);
		imageLab1.setBounds(470, 10, 300, 500);
		imageLab2.setBounds(60, 300, 350, 250);
		imagePanel.setLayout(null);
		imagePanel.add(imageLab);
		imagePanel.add(imageLab1);
		imagePanel.add(imageLab2);
	}

	public static void main(String argv[]) {
		Acceuil acceuil = new Acceuil();
		//AjoutResto ajoutResto = new AjoutResto();
		//ajoutResto.setVisible(true);
		//DBManager dbManager = new DBManager ();
		//ConnexionUserFrame bUser = dbManager.existUser("pat", "p17");
		//System.out.print(bUser.getNomUser());
		///xxxxxxxxxxxxxxxxxxxxxxxxxx
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if (arg0.getSource()==conMenu){
			
			Utilisateur user = new Utilisateur();
		}
		
		if (arg0.getSource()==deconMenu){
		   fenPrinc.dispose();
		}
		
		if(arg0.getSource() == addRestau){
		
			@SuppressWarnings("unused")
			Restaurant restaurant = new Restaurant();
		   //ConnexionUserFrame connex = new ConnexionUserFrame();
			//AjoutResto addResto = new AjoutResto();
		}
		if(arg0.getSource() == addPlat){
		     
				@SuppressWarnings("unused")
				Plat plat = new Plat();	
			}
		if(arg0.getSource()==addComment){
			System.out.println("commentaire");
			@SuppressWarnings("unused")
			Commentaire comment = new Commentaire();
			
		}
		if(arg0.getSource()== listRestau){
			RestaurantAffiche listResto = new RestaurantAffiche();
		}
		if(arg0.getSource()== listPlat){
			PlatAffiche listPlat = new PlatAffiche();
		}
	}	
			
		
	}

		
	


